package com.lee.config;

import com.volcengine.ark.runtime.service.ArkService;
import okhttp3.ConnectionPool;
import okhttp3.Dispatcher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
public class ArkServiceConfig {

    @Bean
    public ArkService getArkService() {
        // 从环境变量中获取Ark API密钥
        String apiKey = System.getenv("ARK_API_KEY");
        // 创建一个连接池，最大连接数为5，空闲连接的存活时间为1秒
        ConnectionPool connectionPool = new ConnectionPool(5, 1, TimeUnit.SECONDS);
        // 创建一个调度器，用于管理请求的执行
        Dispatcher dispatcher = new Dispatcher();
        // 构建Ark服务实例，配置调度器、连接池、基础URL和API密钥
        ArkService service = ArkService.builder()
                .dispatcher(dispatcher)
                .connectionPool(connectionPool)
                .baseUrl("https://ark.cn-beijing.volces.com/api/v3")
                .apiKey(apiKey)
                .build();
        return service;
    }
}
